package com.tegtech.core.config;

import javax.servlet.DispatcherType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.tegtech.core.filter.RepeatableFilter;
import com.tegtech.core.filter.SignatureFilter;
import com.tegtech.core.filter.XssFilter;

/**
 * Filter配置
 *
 * @author Jun
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Configuration
public class FilterConfig {
	
	@Autowired
	private XssFilter xssFilter;
	@Autowired
	private RepeatableFilter repeatableFilter;
	@Autowired
	private SignatureFilter signatureFilter;
	
	@Bean
	public FilterRegistrationBean xssFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setDispatcherTypes(DispatcherType.REQUEST);
		registration.setFilter(xssFilter);
		registration.addUrlPatterns("/*");
		registration.setName("xssFilter");
		registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
		return registration;
	}

	@Bean
	public FilterRegistrationBean repeatableFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(repeatableFilter);
		registration.addUrlPatterns("/*");
		registration.setName("repeatableFilter");
		registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
		return registration;
	}
	
	@Bean
	public FilterRegistrationBean signatureFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(signatureFilter);
		registration.addUrlPatterns("/*");
		registration.setName("signatureFilter");
		registration.setOrder(1);
		return registration;
	}

}
